package com.tfy.liquor.controller;

import com.tfy.liquor.bean.Result;
import com.tfy.liquor.bean.UserPurse;
import com.tfy.liquor.service.UserPurseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Locale;

@RestController
@RequestMapping("/userPurse")
public class UserPurseController {
    @Autowired
    private UserPurseService userPurseService;

    // 创建钱包
    @RequestMapping("/createUserPurse")
    public Result createUserPurse(UserPurse userPurse) {
        if (null == userPurse) {
            return new Result().bad_CodeIsNull();
        }
        if (userPurseService.createUserPurse(userPurse)) {
            return new Result().ok("钱包创建成功！");
        }
        return new Result().error("钱包创建失败！");
    }

    // 根据用户编号获取钱包信息
    @RequestMapping("/getUserPurseByUserId")
    public Result getUserPurseByUserId(Long userId) {
//        System.err.println(userId);
        if (null == userId) {
            return new Result().bad_CodeIsNull();
        }
        return new Result(userPurseService.getUserPurseByUserId(userId)).ok();
    }

    // 修改钱包操作密码
    @RequestMapping("/editUserPurseOpCode")
    public Result editUserPurseOpCode(UserPurse userPurse, String oldOpCode) {
        if (null == userPurse || null == oldOpCode || "".equals(oldOpCode.trim())) {
            return new Result().bad_CodeIsNull();
        }
        return userPurseService.editUserPurseOpCode(userPurse, oldOpCode);
    }
}
